/*
 * @:同步循环钩子 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-06-28 09:26:41
 * @LastEditors: ziwei
 * @LastEditTime: 2022-02-11 14:09:55
 */

const { SyncLoopHook } = require('tapable');
//SyncLoopHook 就是不停的循环执行回调函数，直接结果为undefined为止，每次循环都是从头开始执行
//如果返回值为undefined就会往后执行下一个函数
const hook = new SyncLoopHook(['xx', 'yy']);

let counter1 = 0;
let counter2 = 0;
let counter3 = 0;
let counter4 = 0;

hook.tap("1",(name,age)=>{
    console.log(1,'counter',counter1);
    if(++counter1===1){
        counter1=0;
        return
    }
    return true;
})

hook.tap("2", (name, age) => {
    console.log(2, 'counter', counter2);
    if (++counter2 === 2) {
        counter2 = 0;
        return
    }
    return true;
})

hook.tap("3", (name, age) => {
    console.log(3, 'counter', counter3);
    if (++counter3 === 3) {
        counter3 = 0;
        return
    }
    return true;
})

// hook.tap("4", (name, age) => {
//     console.log(4, 'counter', counter1);
//     if (++counter4 === 4) {
//         counter4 = 0;
//         return
//     }
//     return true;
// })

hook.call("zhufeng",10);

/* 1 counter 0
2 counter 0
1 counter 0
2 counter 0
3 counter 0
1 counter 0
2 counter 0
1 counter 0
2 counter 0
3 counter 0
1 counter 0
2 counter 0
1 counter 0
2 counter 0
3 counter 0 */
